package com.pignest.hotel.module.user.ui;

import java.util.List;
import java.util.Set;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

import com.pignest.hotel.service.DictionaryService;
import com.pignest.hotel.service.RoomService;
import com.pignest.hotel.spring.Services;

public class DictListBox extends Listbox implements EventListener {

	@Override
	public void onEvent(Event arg0) throws Exception {
		// TODO Auto-generated method stub

	}
	public String name;
	public List dict;
	public void QueryDict(){
		DictionaryService dictionaryService=Services.getDictionaryService();
		 this.setDict(dictionaryService.listDictionaries(this.name));
	}
	public void onCreate() {
		this.QueryDict();
		System.out.println("dict size="+dict.size());
	}
	public boolean removeSelected() {
		if (getSelectedCount() == 0)
			return false;
		Set<Listitem> selected = getSelectedItems();
		RoomService roomService = Services.getRoomService();
		for (Listitem item : selected) {
			if (roomService.hasRooms((String)item.getAttribute("roomTypeId")))
				return false;
			System.out.println(item.getAttribute("roomTypeId"));
		}
		for (Listitem item : selected) {
			roomService.removeRoomType(roomService.getRoomType((String)item.getAttribute("roomTypeId")));
		}
		return true;
	}
	public void removeAll() {
		int count = getItemCount();
		for (int i = count - 1; i >= 0; i--) {
			removeItemAt(i);
		}
	}
	public String getName() {
		System.out.println("是否可以获取到name 的值:"+this.name);
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public List getDict() {
		return dict;
	}
	public void setDict(List dict) {
		this.dict = dict;
	}
	
}
